package com.xjtu.platform.security.forgetPwd.Impl;

import com.xjtu.platform.common.Utils;
import com.xjtu.platform.security.forgetPwd.ForgetPwdDto;
import com.xjtu.platform.security.forgetPwd.ForgetPwdService;
import com.xjtu.platform.security.forgetPwd.dao.ForgetPwdDao;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Map;

@Service
@Transactional
public class ForgetPwdServiceImpl implements ForgetPwdService {
    @Resource
    private ForgetPwdDao forgetPwdDao;

    @Override
    public Map<String, Object> getEmail(ForgetPwdDto forgetPwdDto) {
        return Utils.getPage(forgetPwdDto,()->forgetPwdDao.getEmail(forgetPwdDto));
    }

    @Override
    public int getFlag(ForgetPwdDto forgetPwdDto) {
        try {
            return forgetPwdDao.getCode(forgetPwdDto);
        }catch (Exception e){
            e.printStackTrace();
            return 0;
        }
    }

    @Override
    public boolean updatePwd(ForgetPwdDto forgetPwdDto) {
        try {
           forgetPwdDao.updatePwd(forgetPwdDto);
            return true;
        }catch (Exception e){
            e.printStackTrace();
            return false;
        }
    }

    @Override
    public boolean insertFlag(ForgetPwdDto forgetPwdDto, int code) {
        try {
            forgetPwdDao.insertFlag(forgetPwdDto,code);
            return true;
        }catch (Exception e){
            e.printStackTrace();
            return false;
        }
    }

    @Override
    public long getCachetime(String user_id) {
        try {
            return forgetPwdDao.getCachetime(user_id);
        }catch (Exception e){
            e.printStackTrace();
            return 0;
        }
    }
}
